<?php
class Loader {
	
	private function __construct() {
		
	}
	
	public static function loadController($controllerName) {
		$controllerName .= 'Controller';
		$controllerName = ucfirst($controllerName);
		if(file_exists(__CONTROLLER_PATH.$controllerName.'.class.php')) {	
			if(!class_exists($controllerName))
				require_once(__CONTROLLER_PATH.$controllerName.'.class.php');
			return new $controllerName();
		}
		else if(!class_exists('UserController'))
			require_once(__CONTROLLER_PATH."UserController.class.php");
		return new UserController();
	}
	
	public static function loadModel($modelName, $params=array()) {
		$modelName = file_exists(__MODEL_PATH.ucfirst($modelName).".class.php") ?
			$modelName : "Model";
		require_once(__MODEL_PATH.$modelName.".class.php");
		return new $modelName($params);
	}
	
	public static function loadView($viewName, $params=array()) {
		$viewName = file_exists(__VIEW_PATH.ucfirst($viewName).".class.php") ?
			$viewName : "View";
		require_once(__VIEW_PATH.$viewName.".class.php");
		return new $viewName($params);
	}
	
	public static function loadTemplate($templateName, $params=array()) {
		$templateName = file_exists(__TEMPLATE_PATH.$templateName.".php") ?
				$templateName.".php" : 
				"../index.php";
		require_once(__TEMPLATE_PATH.$templateName);
	}

}